<!--
 * @Date: 2022-03-01 11:50:06
 * @Author: 陶子
 * @LastEditTime: 2023-06-25 17:44:43
 * @FilePath: \jk_one-stop_pc\src\views\workManagement\productTask\productTaskList.vue
 * @pageName: 这是--(生产任务配置列)--页面
-->
<template>
  <div class="pagebox">
    <!--  -->
    <crumbs @goBack="() => {}" :superiorMenu="['生产管理']" currentMenu="生产任务"></crumbs>
    <div class="cardBox">
      <div class="cardTwo">
        <a-card :bordered="false" size="small" style="height: 100%; margin-top: 12px">
          <div class="topBox">
            <div>
              <a-button @click="handleShowFilter" icon="filter" style="margin-right: 10px">
                筛选 <span style="color: #1890ff; margin-left: 5px">{{ filteredNums }}</span>
              </a-button>
              <a-button @click="showColumn" icon="unordered-list" style="margin-right: 10px"> 设置列 </a-button>
            </div>
            <div></div>
          </div>
          <a-table
            v-if="tableShow"
            :key="tableKey"
            row-key="id"
            :columns="columns"
            :data-source="tableData"
            :pagination="false"
            :scroll="{ x: computedX, y: 'calc(100vh - 366px)' }"
            :row-selection="{
              selectedRowKeys: selectedRowKeys,
              columnTitle: ' ',
              onChange: onSelectChange,
            }"
            @change="tableChange"
            :components="drag(columns, 'PRODUCT_TASK_LIST')"
          >
            <!-- 输入框搜索 -->
            <div slot="searchDropdown" slot-scope="{ confirm, clearFilters, column }" class="searchWorkOreder">
              <a-input
                :placeholder="checkPlaceholder(column.dataIndex)"
                v-model="filterForm[column.dataIndex]"
                style="width: 188px; display: block"
              />
              <a-button
                type="primary"
                style="width: 80px; margin-left: 20px; display: block"
                @click="() => pubSearch(confirm, column.dataIndex, clearFilters)"
              >
                搜索
              </a-button>
            </div>
            <a-icon
              slot="searchIcon"
              slot-scope="filtered"
              type="search"
              :style="{ color: filtered ? '#108ee9' : undefined }"
            />
            <!-- 选择搜索 -->
            <div slot="selectDropdown" slot-scope="{ confirm, clearFilters, column }" class="searchWorkOreder">
              <a-select
                mode="multiple"
                :placeholder="checkPlaceholder(column.dataIndex)"
                style="width: 200px"
                v-model="filterForm[column.dataIndex]"
              >
                <a-select-option v-for="item in checkList(column.dataIndex)" :key="item.value" :value="item.value">
                  {{ item.label }}
                </a-select-option>
              </a-select>
              <a-button
                type="primary"
                style="width: 80px; margin-left: 20px; display: block"
                @click="() => pubSearch(confirm, column.dataIndex, clearFilters)"
              >
                搜索
              </a-button>
            </div>
            <a-icon
              slot="selectIcon"
              slot-scope="filtered"
              type="filter"
              :style="{ color: filtered ? '#108ee9' : undefined }"
            />
            <a-icon
              slot="dateIcon"
              slot-scope="filtered"
              type="filter"
              :style="{ color: filtered ? '#108ee9' : undefined }"
            />
            <div slot="selectPeople" slot-scope="{ confirm, clearFilters, column }" class="searchWorkOreder">
              <j-select-user-by-dep
                @changeRow="usercreateByFun"
                v-model="filterForm.createByList"
                :seldep="true"
                :modalWidth="1000"
                :multi="true"
                v-if="column.dataIndex == 'createByText'"
              ></j-select-user-by-dep>
              <j-select-user-by-dep
                @changeRow="userupdateByFun"
                v-model="filterForm.updateByList"
                :seldep="true"
                :modalWidth="1000"
                :multi="true"
                v-if="column.dataIndex == 'updateByText'"
              ></j-select-user-by-dep>
              <a-button
                type="primary"
                style="width: 80px; margin-left: 20px; display: block"
                @click="() => pubSearch(confirm, column.dataIndex, clearFilters)"
              >
                搜索
              </a-button>
            </div>
            <!-- 插槽显示 -->
            <span
              slot="orderCode"
              @click="WidDetail(record)"
              slot-scope="text, record"
              style="color: #1890ff; cursor: pointer"
              >{{ text }}</span
            >
            <span slot="planStartTime" slot-scope="text, record">{{
              record.planStartTime + ' ~' + record.planEndTime
            }}</span>
            <span slot="planEndTime" slot-scope="text, record" :style="{ color: checkColor(record) }">{{
              moment(record.planEndTime).format('YYYY-MM-DD HH:mm')
            }}</span>
            <span slot="processCode" slot-scope="text, record" :title="record.processCode">{{
              record.processCode
            }}</span>
            <span slot="processName" slot-scope="text, record" :title="record.processName">{{
              record.processName
            }}</span>
            <span slot="goodsCode" slot-scope="text, record" :title="record.goodsCode">{{ record.goodsCode }}</span>
            <span slot="goodsName" slot-scope="text, record" :title="record.goodsName">{{ record.goodsName }}</span>
            <span slot="orderStatus" slot-scope="text, record">
              <span v-if="record.orderStatus == '0'" style="color: #ff943e">未开始 </span>
              <span v-if="record.orderStatus == '1'" style="color: #1890ff">生产中</span>
              <span v-if="record.orderStatus == '2'" style="color: #00b042">已完成</span>
              <span v-if="record.orderStatus == '3'" style="color: #888888">已取消</span>
            </span>
            <span
              slot="reportStatus"
              slot-scope="text, record"
              :style="{ color: text == 'yes' ? '#1890ff' : '#888888' }"
              >{{ record.reportStatusName }}</span
            >
            <span slot="qualifiedNum" slot-scope="text">
              <div>{{ numFormat(text) || '-' }}</div>
            </span>
            <span slot="notQualifiedNum" slot-scope="text">
              <div>{{ numFormat(text) || '-' }}</div>
            </span>
            <span slot="availableNumForReport" slot-scope="text">
              <div>{{ numFormat(text) || '-' }}</div>
            </span>
            <!-- 操作 -->
            <span slot="actions" slot-scope="text, record">
              <a @click="openDetail(record)" v-if="hasButton('productTask:detail')">详情</a>
              <span>
                <a-divider type="vertical" v-if="hasButton('productTask:detail') && (hasButton('productTask:edit') || hasButton('productTask:delete'))" />
                <a-dropdown>
                  <a class="ant-dropdown-link" @click="(e) => e.preventDefault()"
                     v-if="hasButton('productTask:edit') || hasButton('productTask:delete')">
                    更多
                    <a-icon type="down" />
                  </a>
                  <a-menu slot="overlay">
                    <a-menu-item :key="1">
                      <a-button type="link" @click="editForm(record)" v-if="hasButton('productTask:edit')">编辑 </a-button>
                    </a-menu-item>

                    <a-menu-item :key="5">
                      <a-button type="link" @click="delconta(record.id)" style="color: red" v-if="hasButton('productTask:delete')">删除 </a-button>
                    </a-menu-item>
                  </a-menu>
                </a-dropdown>
              </span>
            </span>
          </a-table>
        </a-card>
      </div>
    </div>
    <div
      class="uni-card pagination-contian"
      :style="{
        position: 'fixed',
        bottom: 0,
        right: 0,
        zIndex: 2,
        left: collapsed ? '197px' : '76px',
        background: '#fff',
        paddingLeft: '43px',
      }"
    >
      <div class="check-contain" style="display: inline-block">
        <a-checkbox :indeterminate="listIndeterminate" :checked="listCheckAll" @change="onCheckAllChange"></a-checkbox>
        <span class="pubColor" style="margin: 0 16px 0 24px" @click="batchAction()" v-if="hasButton('productOrder:delete')">删除</span>
        <span>
          {{ `已选 ${selectedRowKeys.length}/${total} 项` }}
          <span class="pubColor" @click="clearArr" style="margin: 0 10px">清空</span>
        </span>
      </div>
      <div style="display: inline-block; float: right">
        <a-pagination
          :total="total"
          v-model="current"
          :page-size-options="pageSizeOptions"
          :page-size="pageSize"
          @change="onChangePage"
          @showSizeChange="onShowSizeChange"
          show-quick-jumper
          show-size-changer
        />
      </div>
    </div>
    <SetColumn
      columnName="设置列"
      ref="SetColumn"
      v-if="showSetColumn"
      @sureBtn="sureBtn"
      @cancelBtn="showSetColumn = false"
    />
    <!-- 筛选抽屉 -->
    <a-drawer width="500" :closable="true" :visible="showFilter" @close="closeFilter">
      <div class="filter-body">
        <div slot="title" class="uni-card filter-tit">
          筛选 <span class="filter-num">{{ filteredNums }}</span>
        </div>
        <div v-if="filteredNums > 0" class="tagContian">
          <div v-for="(item, i) in filteredList" :key="i" v-show="checkShow(item.text)" class="tag-wrap">
            <span class="filter-tag" @click="delFiltered(item.key)">
              <span class="tag-text">{{ `${item.title}：${item.text}` }}</span>
              <a-icon type="close" style="float: right" />
            </span>
          </div>
        </div>
        <div style="overflow-y: scroll; flex: 1; padding: 0">
          <div class="uni-card" style="background: #fff">
            <a-form-model ref="ruleForm" layout="vertical" :model="filterForm">
              <a-form-model-item label="工单编号">
                <a-input v-model="filterForm.orderCode" placeholder="请输入" />
              </a-form-model-item>
              <a-form-model-item label="物品编号">
                <a-input v-model="filterForm.serialCode" placeholder="请输入" />
              </a-form-model-item>
              <a-form-model-item label="物品名称">
                <a-input v-model="filterForm.serialName" placeholder="请输入" />
              </a-form-model-item>
              <a-form-model-item label="规格">
                <a-input v-model="filterForm.serialSpecifications" placeholder="请输入" />
              </a-form-model-item>
              <a-form-model-item label="工序名称">
                <a-select mode="multiple" placeholder="请选择" v-model="filterForm.processesName" allowClear>
                  <a-select-option v-for="item in reportSelectList" :key="item.value" :value="item.value">
                    {{ item.label }}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
              <a-form-model-item label="工单状态">
                <a-select mode="multiple" placeholder="请选择" v-model="filterForm.orderStatus" allowClear>
                  <a-select-option v-for="item in statusList" :key="item.value" :value="item.value">
                    {{ item.label }}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
              <a-form-model-item style="width: 100%" label="创建人">
                <j-select-user-by-dep
                  @changeRow="usercreateByFun"
                  v-model="filterForm.createByList"
                  :seldep="true"
                  :modalWidth="1000"
                  :multi="true"
                ></j-select-user-by-dep>
              </a-form-model-item>
              <a-form-model-item label="更新人">
                <j-select-user-by-dep
                  @changeRow="userupdateByFun"
                  v-model="filterForm.updateByList"
                  :seldep="true"
                  :modalWidth="1000"
                  :multi="true"
                ></j-select-user-by-dep>
              </a-form-model-item>
            </a-form-model>
          </div>
        </div>
        <div class="footer-submit">
          <a-button class="margin-btn" @click="resetFilter">重置</a-button>
          <a-button type="primary" @click="handleFilter">确定</a-button>
        </div>
      </div>
    </a-drawer>
    <!-- 批量modal——无法批量 -->
    <a-modal
      :bodyStyle="{ padding: '32px 32px 24px', boxSizing: 'border-box' }"
      :maskClosable="false"
      v-model="batchOverFiil"
      :closable="false"
      on-ok="setLimit"
      width="460px"
    >
      <template slot="footer">
        <a-button key="back" @click="batchOverFiil = false"> 取消 </a-button>
        <a-button key="submit" @click="batchOverFiil = false" type="primary"> 确定 </a-button>
      </template>
      <div class="modalTopBox">
        <a-icon type="close-circle" theme="filled" style="color: red; font-size: 22px" />
        <span>无法批量报工</span>
      </div>
      <div class="smallFont">{{ dialogMessage }}</div>
    </a-modal>
    <editForm @confirm="confirm" ref="editForm"></editForm>
    <taskDetail ref="taskDetail"></taskDetail>
    <windowDetail ref="windowDetail"></windowDetail>
    <!-- <BatchModal ref="batchModal" @reportBatchSuccess="clearArr(true)" />
    <windowDetail ref="windowDetail"></windowDetail>

    <materialRequisitionForm ref="materialRequisitionForm" @refresh="pubSearch(() => {})"></materialRequisitionForm>
    <addMaterialRequisitionForm
      ref="addMaterialRequisitionForm"
      @refresh="pubSearch(() => {})"
    ></addMaterialRequisitionForm>
    <returnMaterialForm ref="returnMaterialForm" @refresh="pubSearch(() => {})"></returnMaterialForm>
    <report ref="report" @refresh="pubSearch(() => {})"></report> -->
  </div>
</template>
<script>
import moment from 'moment'
import {
  taskListApi,
  batchValidOrUpdateStatus,
  processTaskCompletionStatics,
  deleteTaskApi,
  deleteCol,
  idsDel,
  ProcessesList,
  getOrderStatus,
} from '@/api/productOrder'
import { columns, allColumn } from './allColumn.js'
import { getNewColumns, compareDate, subStrText, numFormat } from '@/utils/util'
import SetColumn from '@/pubComponent/SetColumn.vue'
import BatchModal from '@/views/workManagement/productTask/BatchModal.vue'
import crumbs from '@/components/crumbs.vue'
import { mapState } from 'vuex'
import tableDragResize from '@/mixins/tableDragResize'
import windowDetail from '@/views/workManagement/workOrder/workOrderDetail'
import taskDetail from '@/views/workManagement/productTask/taskDetail'
import editForm from '@/views/workManagement/productTask/editFrom'
import tableDynamicField from '@/mixins/tableDynamicField'
import { APILX } from '@/api/requestLx'
import { hasButton } from '@/utils/hasPermission'

const actionArr = [
  {
    fixed: 'right',
    title: '操作',
    align: 'left',
    dataIndex: 'actions',
    ellipsis: true,
    width: 130,
    scopedSlots: { customRender: 'actions' },
  },
]
export default {
  mixins: [tableDragResize, tableDynamicField],
  components: {
    crumbs,
    SetColumn,
    BatchModal,
    windowDetail,
    taskDetail,
    editForm,
    materialRequisitionForm: (resolve) =>
      require(['@/views/workManagement/materialRequisition/materialRequisitionForm'], resolve),
    addMaterialRequisitionForm: (resolve) =>
      require(['@/views/workManagement/addMaterialRequisition/addMaterialRequisitionForm'], resolve),
    returnMaterialForm: (resolve) => require(['@/views/workManagement/returnMaterial/returnMaterialForm'], resolve),
    report: (resolve) => require(['@/views/workManagement/productTask/report'], resolve),
  },
  data() {
    return {
      numFormat,
      moment,
      subStrText,
      dialogMessage: '',
      formType: 7,
      actionArr,
      isOpen: true,
      columns,
      allColumn,
      tableData: [],
      selectedRowKeys: [],
      batchOverFiil: false,
      batchOverSuccess: false,
      chooseArr: [],
      //全选按钮
      listIndeterminate: false,
      listCheckAll: false,
      current: 1,
      total: 0,
      pageSize: 30,
      pageSizeOptions: ['10', '20', '30', '40', '50'],
      showSetColumn: false,
      // 抽屉数据
      showFilter: false, // 筛选抽屉
      modelStartTime: [],
      modelEndTime: [],
      modelCreateTime: [],
      realFilterForm: {},
      tableFilterForm: {},
      filterForm: {
        // orderCode: [],
        // reportStatus: ['yes'],
        // orderCode: '',
        // goodsName: '',
        // goodsSpec: '',
        // planStartTime: [],
        // planEndTime: [],
        // createTime: [],
        orderCode: '',
        serialCode: '',
        serialName: '',
        serialSpecifications: '',
        processesName: [],
        orderStatus: [],
        createByList: '',
        updateByList: '',
      },
      filteredFormLable: {
        orderCode: '工单编号',
        serialCode: '物品编号',
        serialName: '物品名称',
        serialSpecifications: '规格',
        processesName: '工序名称',
        orderStatus: '工单状态',
        createByList: '创建人',
        updateByList: '更新人',
      },
      statusList: [],
      reportSelectList: [],
      keyword: '',
      messSingleProcessTaskStaticsDtoList: [],
      processId: '',
      tableKey: 1.9,
      EntityName: this.BUSI_CONST.Entity.PRODUCT_TASK_LIST,
    }
  },
  computed: {
    ...mapState({
      collapsed: (state) => state.user.collapsedAno,
    }),
    computedWidth() {
      let str = {}
      if (this.isOpen && this.collapsed) {
        str.width = 'calc(100vw - 350px)'
      }
      if (!this.isOpen && this.collapsed) {
        str.width = 'calc(100vw - 130px)'
      }
      if (this.isOpen && !this.collapsed) {
        str.width = 'calc(100vw - 455px)'
      }
      if (!this.isOpen && !this.collapsed) {
        str.width = 'calc(100vw - 230px)'
      }
      return str
    },
    computedX() {
      let xnum = 0
      for (let item of this.columns) {
        xnum += Number(item.width)
      }

      return xnum
    },
    realFilterNum() {
      let nums = 0
      for (let key in this.realFilterForm) {
        if (this.realFilterForm[key] != '') {
          nums += 1
        }
      }
      return nums
    },
    filteredNums() {
      let nums = 0
      for (let key in this.filterForm) {
        if (this.filterForm[key] != '' && this.filterForm[key] != null) {
          nums += 1
        }
      }
      return nums
    },
    filteredList() {
      let list = []
      for (let key in this.filterForm) {
        if (this.filteredFormLable[key] == '工单状态') {
          let strArr = ''
          for (let item of this.filterForm[key]) {
            for (let each of this.statusList) {
              if (item == each.value) {
                strArr += each.label + '，'
              }
            }
          }
          if (strArr) {
            strArr = strArr.substring(0, strArr.length - 1)
          }
          list.push({
            title: this.filteredFormLable[key],
            text: strArr,
            key,
          })
        } else if (this.filteredFormLable[key] == '工序名称') {
          let strArr = ''
          for (let item of this.filterForm[key]) {
            for (let each of this.reportSelectList) {
              if (item == each.value) {
                strArr += each.label + '，'
              }
            }
          }
          if (strArr) {
            strArr = strArr.substring(0, strArr.length - 1)
          }
          list.push({
            title: this.filteredFormLable[key],
            text: strArr,
            key,
          })
        } else if (this.filterForm[key] !== '' && this.filteredFormLable[key] == '创建人') {
          list.push({
            title: this.filteredFormLable[key],
            text: this.showcreateBy,
            key,
          })
        } else if (this.filterForm[key] !== '' && this.filteredFormLable[key] == '更新人') {
          list.push({
            title: this.filteredFormLable[key],
            text: this.showupdateBy,
            key,
          })
        } else {
          list.push({
            title: this.filteredFormLable[key],
            text: this.filterForm[key],
            key,
          })
        }
      }
      return list
    },
  },
  created() {
    // let oldValue = localStorage.getItem(this.BUSI_CONST.Entity.PRODUCT_TASK_LIST)
    // this.columns = getNewColumns(this.allColumn, JSON.parse(oldValue), actionArr, this.columns)
    let leftObj = {
      keyword: this.keyword,
    }
    this.ProcessesList()
    // this.getLeftData(leftObj)
    let obj = {
      pageNo: this.current,
      pageSize: this.pageSize,
      reportStatus: 'yes',
    }
    this.getFieldsLable()
    // this.getData(obj)
  },
  methods: {
    hasButton,
    async getFieldsLable() {
      let res = await APILX.formTypeExtendedFieldList({ formType: this.formType })
      if (res.code == 200 && res.result) {
        let formTypeExtendedFields = res.result || []

        formTypeExtendedFields.forEach((fields) => {
          this.filteredFormLable['extDataJson.' + fields.fieldKey] = fields.fieldName
        })
      }
    },

    confirm() {
      this.handleFilter()
    },
    ProcessesList() {
      let param = {
        pageNo: 1,
        pageSize: 9999,
      }
      getOrderStatus().then((res) => {
        if (res.code == 200) {
          this.statusList = res.result.map((el) => {
            return {
              value: el.value,
              label: el.text,
            }
          })
          this.filterForm.orderStatus = ['1']
          let params = this.formatData()
          this.current = 1
          let obj = {
            pageNo: this.current,
            pageSize: this.pageSize,
            ...params,
          }
          this.getData(obj)
        }
      })
      ProcessesList(param).then((res) => {
        if (res.code == 200) {
          this.reportSelectList = res.result.records.map((el) => {
            return {
              value: el.id,
              label: el.processesName,
            }
          })
        }
      })
    },
    usercreateByFun(storeVals, row) {
      // this.filterForm.createByList = ''
      let newArr = []
      let arrTwo = []
      for (let item of row) {
        newArr.push(item.id)
        arrTwo.push(item.realname)
      }

      if (newArr.length > 0) {
        // this.filterForm.createByList = newArr.join(',')
      }
      if (arrTwo.length > 0) {
        this.showcreateBy = arrTwo.join(',')
      }
      this.requestData()
    },
    userupdateByFun(storeVals, row) {
      // this.filterForm.updateByList = ''
      let newArr = []
      let arrTwo = []
      for (let item of row) {
        newArr.push(item.id)
        arrTwo.push(item.realname)
      }

      if (newArr.length > 0) {
        // this.filterForm.updateByList = newArr.join(',')
      }
      if (arrTwo.length > 0) {
        this.showupdateBy = arrTwo.join(',')
      }
      this.requestData()
    },
    // 创建人
    createByFun(storeVals, row) {
      let newArr = []
      let arrTwo = []
      for (let item of row) {
        newArr.push(item.id)
        arrTwo.push(item.realname)
      }
      if (arrTwo.length > 0) {
        this.showcreateBy = arrTwo.join(',')
      }
    },
    updateByFun(storeVals, row) {
      let newArr = []
      let arrTwo = []
      for (let item of row) {
        newArr.push(item.id)
        arrTwo.push(item.realname)
      }

      if (arrTwo.length > 0) {
        this.showupdateBy = arrTwo.join(',')
      }
    },
    editForm(record) {
      this.$refs.editForm.initDetail(record)
    },

    delconta(id) {
      let that = this
      that.$antdConfirm({
        title: '确定删除任务吗?',
        content: '任务删除后，将同时删除关联的报工记录，删除后不可恢复。',
        iconType: 'exclamation-circle',
        onOk: () => {
          deleteCol({ id }).then((res) => {
            if (res.code == 200) {
              that.$antdMessage.success('删除成功')
              let params = this.formatData()
              this.current = 1
              let obj = {
                pageNo: this.current,
                pageSize: this.pageSize,
                ...params,
              }
              that.getData(obj)
            } else {
              that.$antdMessage.error(res.message)
            }
          })
        },
      })
    },
    checkColor(row) {
      let currentTime = new Date().valueOf()
      let colorStr = ''
      if (row.orderStatus == 'notStarted' || row.orderStatus == 'inProduction') {
        // let currentTime = new Date(+new Date() + 8 * 3600 * 1000).toJSON().substr(0, 19).replace('T', ' ')
        // let checkResult = compareDate(row.planEndTime, currentTime)
        let deadLine = moment(row.planEndTime).valueOf()
        let checkResult = currentTime > deadLine
        if (checkResult) {
          colorStr = '#ff4d4f'
        } else {
          colorStr = ''
        }
      } else {
        colorStr = ''
      }
      return colorStr
    },
    openDetail(row) {
      this.$refs.taskDetail.initDetail(row)
    },
    WidDetail(row) {
      let data = {
        id: row.orderId,
      }
      this.$refs.windowDetail.initDetail(data)
    },
    checkVisible(row) {
      if (
        row.reportStatus == 'yes' ||
        row.orderStatus == 'notStarted' ||
        row.orderStatus == 'inProduction' ||
        row.orderStatus == 'abolished'
      ) {
        return true
      } else {
        return false
      }
    },
    itemClick(item, index) {
      if (item.processId != this.processId) {
        for (let each of this.messSingleProcessTaskStaticsDtoList) {
          each.isSelect = false
        }
        this.messSingleProcessTaskStaticsDtoList[index].isSelect = true
        this.processId = item.processId
        let params = this.formatData()
        this.current = 1
        let obj = {
          pageNo: this.current,
          pageSize: this.pageSize,
          ...params,
        }
        let secondParams = true
        this.getData(obj, secondParams)
      }
    },
    getLeftData(obj) {
      let params = {
        ...obj,
        type: 'production',
      }
      processTaskCompletionStatics(params).then((res) => {
        if (res.success) {
          let resultList = res.result.messSingleProcessTaskStaticsDtoList
          this.messSingleProcessTaskStaticsDtoList = []
          for (let item of resultList) {
            let resultObj = {}
            for (let i in item) {
              resultObj[i] = item[i]
              resultObj.isSelect = false
            }
            this.messSingleProcessTaskStaticsDtoList.push(resultObj)
          }
        } else {
          this.$antdMessage.warning(res.message)
        }
      })
    },
    checkList(dataIndex) {
      if (dataIndex == 'orderStatus') {
        return this.statusList
      } else {
        return this.reportSelectList
      }
    },
    searchProcess(value) {
      let leftObj = {
        keyword: value,
      }
      // this.getLeftData(leftObj)
    },
    clickOrderCode(row) {
      let query = { id: row.orderId }
      this.$refs.windowDetail.initDetail(query)
    },
    // 批量完成
    batchAction() {
      if (this.selectedRowKeys.length == 0) {
        this.$antdMessage.warning('请勾选需要删除的工单')
        return
      }
      let that = this
      that.$antdConfirm({
        title: '确定批量删除工单吗?',
        content: '任务删除后，将同时删除关联的报工记录，删除后不可恢复。',
        iconType: 'exclamation-circle',
        onOk: () => {
          idsDel({ ids: this.selectedRowKeys.join(',') }).then((res) => {
            if (res.code == 200) {
              that.$antdMessage.success('批量删除成功')
              let params = this.formatData()
              this.current = 1
              let obj = {
                pageNo: this.current,
                pageSize: this.pageSize,
                ...params,
              }
              that.getData(obj)
            } else {
              that.$antdMessage.error(res.message)
            }
          })
        },
      })
      // if (this.selectedRowKeys.length > 0) {
      //   this.chooseArr = this.chooseArr.filter((item, index) => {
      //     return this.chooseArr.findIndex((item1) => item1.id == item.id) == index
      //   })
      //   let selectArr = []
      //   for (let itemId of this.selectedRowKeys) {
      //     for (let itemData of this.chooseArr) {
      //       if (itemId == itemData.id) {
      //         selectArr.push(itemData)
      //       }
      //     }
      //   }
      //   this.dialogMessage = ''
      //   let strArr = []
      //   for (let item of selectArr) {
      //     if (item.reportStatus == 'no') {
      //       let str = item.orderCode + '-' + item.processName
      //       strArr.push(str)
      //     }
      //   }
      //   if (strArr.length > 0) {
      //     this.dialogMessage = '任务：' + strArr.join('、') + '，状态不对无法报工'
      //     this.batchOverFiil = true
      //   } else {
      //     this.$refs.batchModal.showModal(selectArr)
      //   }
      //   // console.log('选择的主键是：', this.selectedRowKeys)
      //   // console.log('看看去重的效果吧：', selectArr)
      // } else {
      //   this.$antdMessage.warning('请先选择数据')
      // }
    },
    //操作——报工
    reportAction(row) {
      this.$refs.report.initForm({
        taskId: row.id,
        orderId: row.orderId,
      })
    },
    //操作——各种申请
    applyAction(row, type) {
      let str = ''
      if (type == '申请领料') {
        str = 'materialRequisitionForm'
      } else if (type == '申请补料') {
        str = 'addMaterialRequisitionForm'
      } else {
        str = 'returnMaterialForm'
      }
      if (str) {
        // this.$router.push({
        //   path: str,
        //   query: {
        //     goodsBasicUnitText: row.goodsBasicUnitText,
        //     goodsName: row.goodsName,
        //     orderId: row.orderId,
        //     orderCode: row.orderCode,
        //   },
        // })
        let query = {
          goodsBasicUnitText: row.goodsBasicUnitText,
          goodsName: row.goodsName,
          orderId: row.orderId,
          orderCode: row.orderCode,
        }
        this.$refs[str].initForm(query)
      }
    },
    // 操作——删除
    confirmDelete(row) {
      let obj = {
        id: row.id,
      }
      deleteTaskApi(obj).then((res) => {
        if (res.success) {
          let params = this.formatData()
          this.current = 1
          let obj = {
            pageNo: this.current,
            pageSize: this.pageSize,
            ...params,
          }
          this.getData(obj)
          let leftObj = {
            keyword: this.keyword,
          }
          // this.getLeftData(leftObj)
          this.selectedRowKeys = this.selectedRowKeys.filter((item) => {
            return item != row.id
          })
          this.chooseArr = this.chooseArr.filter((item) => {
            return item.id != row.id
          })
          this.$antdMessage.success('删除成功！')
        } else {
          this.$antdMessage.warning(res.message)
        }
      })
    },
    getData(obj, secondParams) {
      let params = {
        ...obj,
        type: 'production',
        processId: this.processId,
      }
      taskListApi(params).then((res) => {
        if (res.success) {
          if (res.result.total) {
            this.total = res.result.total
          } else {
            this.total = 0
          }
          let copyArr = JSON.parse(JSON.stringify(res.result.records))
          for (let item of copyArr) {
            for (let each in item) {
              if (!item[each] && item[each] != 0) {
                item[each] = '-'
              }
            }
          }
          this.tableData = copyArr
          if (secondParams) {
            this.checkBoxStatus()
          }
        } else {
          this.$antdMessage.warning(res.message)
        }
      })
    },

    /* 打开筛选 */
    handleShowFilter() {
      // this.filterForm = JSON.parse(JSON.stringify(this.realFilterForm))
      this.showFilter = true
    },

    showColumn() {
      this.showSetColumn = true
      this.$nextTick(() => {
        this.$refs.SetColumn.paramsData(this.allColumn, this.BUSI_CONST.Entity.PRODUCT_TASK_LIST, this.columns)
      })
    },
    sureBtn(emitArr) {
      this.columns = getNewColumns(this.allColumn, emitArr, actionArr)
      console.log(this.emitArr)
      localStorage.setItem(this.BUSI_CONST.Entity.PRODUCT_TASK_LIST, JSON.stringify(emitArr))
      this.tableKey += 1
    },
    checkPlaceholder(dataIndex) {
      let str = ''
      switch (dataIndex) {
        case 'orderCode':
          str = '请输入工单编号'
          break
        case 'goodsName':
          str = '请输入产品名称'
          break
        case 'orderStatus':
          str = '请选择生产状态'
          break
        case 'reportStatus':
          str = '请选择报工状态'
          break
        case 'goodsSpec':
          str = '请输入规格'
          break
      }
      return str
    },
    pubSearch(confirm, dataIndex, clearFilters) {
      confirm() //用来关闭搜索弹窗
      // clearFilters() //用来重置搜索内容
      // console.log('这都是啥11：', confirm)
      console.log('这都是啥22：', dataIndex)
      // this.filterForm = JSON.parse(JSON.stringify(this.tableFilterForm))
      // this.realFilterForm = JSON.parse(JSON.stringify(this.tableFilterForm))
      let params = this.formatData()
      this.current = 1
      let obj = {
        pageNo: this.current,
        pageSize: this.pageSize,
        ...params,
      }
      delete obj.processesName //去除processesName字段
      this.getData(obj)
      // console.log('这都是啥33：', clearFilters)
    },
    // table
    tableChange(pagination, filters, sorter, { currentDataSource }) {
      console.log('看看这是啥33：', sorter)
      let params = this.formatData()
      if (sorter.order) {
        let sortType = ''
        if (sorter.order == 'ascend') {
          sortType = 'ASC'
        } else {
          sortType = 'DESC'
        }
        if (sorter.columnKey == 'createTime') {
          sorter.columnKey = 'create_time'
        }
        if (sorter.columnKey == 'updateTime') {
          sorter.columnKey = 'update_time'
        }
        let obj = {
          pageNo: this.current,
          pageSize: this.pageSize,
          ...params,
          sortType: sortType,
          sortColumn: sorter.columnKey,
        }
        this.getData(obj)
      } else {
        let obj = {
          pageNo: this.current,
          pageSize: this.pageSize,
          ...params,
        }
        this.getData(obj)
      }
    },
    onSelectChange(selectedRowKeys, selectedRows) {
      // console.log('第一个参数是；', selectedRowKeys)
      // console.log('第second个参数是；', selectedRows)
      this.chooseArr = this.chooseArr.concat(selectedRows)
      this.selectedRowKeys = selectedRowKeys
      this.checkBoxStatus()
   },
    checkBoxStatus() {
      if (this.selectedRowKeys.length == 0) {
        this.listIndeterminate = false
        this.listCheckAll = false
      } else {
        let tableIds = []
        for (let item of this.tableData) {
          tableIds.push(item.id)
        }
        let checkValue = this.isInclude(tableIds, this.selectedRowKeys)
        console.log()
        console.log('第一个参数是；', checkValue)
        if (checkValue) {
          this.listIndeterminate = false
          this.listCheckAll = true
        } else {
          this.listIndeterminate = true
          this.listCheckAll = false
        }
      }
    },
    isInclude(aa, bb) {
      return aa.every((item) => {
        return bb.some((sub) => {
          return sub === item
        })
      })
    },
    // 全选
    onCheckAllChange(e) {
      if (e.target.checked) {
        for (let item of this.tableData) {
          this.selectedRowKeys = this.selectedRowKeys.filter((each) => {
            return each != item.id
          })
          this.chooseArr = this.chooseArr.filter((every) => {
            return every.id != item.id
          })
          this.selectedRowKeys.push(item.id)
          this.chooseArr.push(item)
        }
      } else {
        for (let item of this.tableData) {
          this.selectedRowKeys = this.selectedRowKeys.filter((each) => {
            return each != item.id
          })
          this.chooseArr = this.chooseArr.filter((every) => {
            return every.id != item.id
          })
        }
      }
      this.checkBoxStatus()
    },
    clearArr(type) {
      this.selectedRowKeys = []
      this.chooseArr = []
      if (type) {
        let params = this.formatData()
        this.current = 1
        let obj = {
          pageNo: this.current,
          pageSize: this.pageSize,
          ...params,
        }
        let secondParams = true
        this.getData(obj, secondParams)
      } else {
        this.checkBoxStatus()
      }
    },
    // 分页
    onChangePage(current, pageSize) {
      this.current = current
      let params = this.formatData()
      let obj = {
        pageNo: this.current,
        pageSize: this.pageSize,
        ...params,
      }
      let secondParams = true
      this.getData(obj, secondParams)
    },
    onShowSizeChange(current, pageSize) {
      this.pageSize = pageSize
      this.current = 1
      let params = this.formatData()
      let obj = {
        pageNo: this.current,
        pageSize: this.pageSize,
        ...params,
      }
      let secondParams = true
      this.getData(obj, secondParams)
    },
    // 抽屉方法
    startTimeChange(a, b) {
      if (!b[0] && !b[1]) {
        this.modelStartTime = []
        this.filterForm.planStartTime = []
      } else {
        this.filterForm.planStartTime = b
      }
    },
    endTimeChange(a, b) {
      if (!b[0] && !b[1]) {
        this.modelEndTime = []
        this.filterForm.planEndTime = []
      } else {
        this.filterForm.planEndTime = b
      }
    },
    timeCreateChange(a, b) {
      if (!b[0] && !b[1]) {
        this.modelCreateTime = []
        this.filterForm.createTime = []
      } else {
        this.filterForm.createTime = b
      }
    },

    /* 确定筛选 */
    handleFilter() {
      console.log('当前选择的是：', this.filterForm)
      let params = this.formatData()
      params.processesName = ''
      this.current = 1
      let obj = {
        pageNo: this.current,
        pageSize: this.pageSize,
        ...params,
      }
      this.getData(obj)
      this.realFilterForm = JSON.parse(JSON.stringify(this.filterForm))
      this.tableFilterForm = JSON.parse(JSON.stringify(this.filterForm))
      this.showFilter = false
    },
    // 筛选传参数据
    formatData() {
      let copyForm = JSON.parse(JSON.stringify(this.filterForm))

      let params = {
        ...copyForm,
      }

      if (copyForm.processesName && copyForm.processesName.length > 0) {
        params.processesIds = copyForm.processesName.join(',')
      } else {
        params.processesName = ''
      }
      if (copyForm.orderStatus && copyForm.orderStatus.length > 0) {
        params.orderStatus = copyForm.orderStatus.join(',')
      } else {
        params.orderStatus = ''
      }
      params.createByIds = copyForm.createByList
      params.updateByIds = copyForm.updateByList
      delete params.createByList
      delete params.updateByList

      for (const key in params) {
        if (Object.hasOwnProperty.call(params, key)) {
          const value = params[key]
          let keys = key.split('.')
          if (keys.length > 1) {
            if (params[key[0]]) {
              params[keys[0]][keys[1]] = value
            } else {
              params[keys[0]] = {}
              params[keys[0]][keys[1]] = value
            }
          }
        }
      }

      return params
    },
    /* 删除已选 */
    delFiltered(key) {
      if (this.filteredFormLable[key] == '生产状态') {
        this.filterForm[key] = []
      } else if (this.filteredFormLable[key] == '报工状态') {
        this.filterForm[key] = []
      } else if (this.filteredFormLable[key] == '计划开始时间') {
        this.modelStartTime = []
        this.filterForm[key] = []
      } else if (this.filteredFormLable[key] == '计划完成时间') {
        this.modelEndTime = []
        this.filterForm[key] = []
      } else if (this.filteredFormLable[key] == '创建时间') {
        this.modelCreateTime = []
        this.filterForm[key] = []
      } else {
        this.filterForm[key] = ''
      }
    },
    /* 重置筛选 */
    resetFilter() {
      this.filterForm = {
        orderStatus: [],
        reportStatus: [],
        orderCode: '',
        goodsName: '',
        goodsSpec: '',
        planStartTime: null,
        planEndTime: null,
        createTime: null,
        createByList: '',
        updateByList: '',
      }
      this.modelStartTime = []
      this.modelEndTime = []
      this.modelCreateTime = []
    },
    /* 关闭筛选 */
    closeFilter() {
      this.showFilter = false
    },
    checkShow(item) {
      let currentBoolean = Array.isArray(item)
      if (currentBoolean) {
        if (item.length == 0) {
          return false
        } else {
          return true
        }
      } else {
        if (item) {
          return true
        } else {
          return false
        }
      }
    },
  },
}
</script>
<style scoped lang="less">
@import '~@/assets/less/public.less';

.flex(@jc, @ai, @fd: row) {
  display: flex;
  justify-content: @jc;
  align-items: @ai;
  flex-direction: @fd;
}

.table-operations {
  margin-bottom: 16px;
}

.table-operations > button {
  margin-right: 8px;
}

.topBox {
  .flex(space-between, center);
  margin-bottom: 16px;
}

.searchWorkOreder {
  .flex(flex-start, center);
  padding: 8px;
}

.pubColor {
  font-size: 14px;
  color: #1890ff;
  cursor: pointer;
}

.pagebox {
  /deep/ .ant-card-body {
    height: calc(100vh - 180px);
    overflow: hidden;
    padding: 20px 16px;
  }
}

.filter-tit {
  background: #fff;
  border-bottom: 1px solid @greyBorder;
  font-size: @fontSize4;
}

.filter-num {
  color: @normalFont;
}

.filter-body {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.margin-btn {
  margin-right: @distance5;
}

.filter-tag {
  display: inline-block;
  position: relative;
  padding: 8px 10px;
  border-radius: 4px;
  font-size: @fontSize1;
  line-height: @fontSize1;
  max-width: 100%;
  background: @greyBg;
  color: @titFont;
  cursor: pointer;

  .tag-text {
    display: inline-block;
    padding-right: 20px;
    max-width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .anticon-close {
    position: absolute;
    right: 8px;
    top: 8px;
  }
}

.tag-wrap {
  margin: 10px 0 0 10px;
}

.searchWorkOreder {
  .flex(flex-start, center);
  padding: 8px;
}

.modalTopBox {
  .flex(flex-start, center);
  margin-bottom: 8px;

  span {
    margin-left: 16px;
    display: block;
    overflow: hidden;
    color: rgba(0, 0, 0, 0.85);
    font-weight: 500;
    font-size: 16px;
    line-height: 1.4;
  }
}

div.listBox {
  height: calc(100% - 77px);
  margin-top: 10px;
  overflow-y: auto;

  div.itemList {
    .flex(space-between, center);
    height: 34px;
    cursor: pointer;
    box-sizing: border-box;
    padding: 0 16px;

    div.itemLeft {
      font-size: 14px;
      color: #444444;
    }

    div.itemRight {
      font-size: 14px;
      color: #444444;
    }

    &:nth-child(n + 2) {
      div.itemLeft {
        font-size: 14px;
        color: #444444;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        width: 130px;
      }

      div.itemRight {
        font-size: 14px;
        color: #444444;
      }
    }
  }

  div.haveColor {
    .flex(space-between, center);
    height: 34px;
    background: #e3f2ff;
    cursor: pointer;
    box-sizing: border-box;
    padding: 0 16px;

    div.itemLeft {
      font-size: 14px;
      color: #1890ff;
    }

    div.itemRight {
      font-size: 14px;
      color: #1890ff;
    }

    &:nth-child(n + 2) {
      div.itemLeft {
        font-size: 14px;
        color: #1890ff;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        width: 130px;
      }

      div.itemRight {
        font-size: 14px;
        color: #1890ff;
      }
    }
  }
}

a {
  margin: 0;
}
.tagContian {
  background: #fff;
  display: flex;
  justify-content: start;
  flex-wrap: wrap;
  padding: 10px 20px;
}
</style>
